package animation;

import main.pak.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.view.View;

public class DrawingTheBall extends View {

	Bitmap _bball;
	int _x, _y;

	// Constructor
	public DrawingTheBall(Context context) {
		super(context);
		_bball = BitmapFactory.decodeResource(getResources(), R.drawable.biball);
		_x = 0;
		_y = 0;
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		
		Rect v_rect = new Rect();
		v_rect.set(0, 0, canvas.getWidth()/2, canvas.getHeight()/2);
		
		Paint v_pnt_blue = new Paint();
		v_pnt_blue.setColor(Color.BLUE);
		v_pnt_blue.setStyle(Paint.Style.FILL);
		
		canvas.drawRect(v_rect, v_pnt_blue);
		
		if(_x < canvas.getWidth())
		{
			_x += 2;
		}
		else {
			_x = 0;
		}
		
		if(_y < canvas.getHeight()){
			_y += 2;
		}
		else {
			_y = 0;
		}
		
		Paint v_pnt_ball = new Paint();
		canvas.drawBitmap(_bball, _x, _y, v_pnt_ball);		
		invalidate();
	}
}
